<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-productVersion-add">
			<div class="form-group">
			<label class="col-sm-3 control-label">所属产品：</label>
			<div class="col-sm-8">
				<select id="product" name="product" class="form-control m-b">
					<option th:each="product:${products}" th:value="${product.id}" th:text="${product.name}" th:disabled="${product.status == '1'}"></option>
				</select>
			</div>
		</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">版本号：</label>
				<div class="col-sm-8">
					<input id="version" name="version" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">版本名称：</label>
				<div class="col-sm-8">
					<input id="name" name="name" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">是否发布：</label>
				<div class="col-sm-8">
					<div class="onoffswitch">
						<input type="checkbox" th:checked="true" class="onoffswitch-checkbox" id="isPublished" name="isPublished">
						<label class="onoffswitch-label" for="isPublished">
							<span class="onoffswitch-inner"></span>
							<span class="onoffswitch-switch"></span>
						</label>
					</div>
				</div>
			</div>
			<!--<div class="form-group">	-->
				<!--<label class="col-sm-3 control-label">是否发布：</label>-->
				<!--<div class="col-sm-8">-->
					<!--<input id="isPublished" name="isPublished" class="form-control" type="text">-->
				<!--</div>-->
			<!--</div>-->
		</form>
	</div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "system/productVersion"
		$("#form-productVersion-add").validate({
			rules:{
                version:{
                    required:true,
                    minlength: 2,
                    maxlength: 20,
				},
                product:{
                    required:true
				},
                isPublished:{
                    required:true
				}
			}
		});
		
		function submitHandler() {
            if ($.validate.form()) {
                add();
            }
	        // if ($.validate.form()) {
	        //     $.operate.save(prefix + "/add", $('#form-productVersion-add').serialize());
	        // }
	    }

        function add() {
            var productId = $("#product").val();
            var productName = $("#product option:selected").text();
            var version = $("input[name='version']").val();
            var versionName = $("input[name='name']").val();
            var isPublished = $("input[name='isPublished']").is(':checked') == true ? 1 : 0;
            $.ajax({
                cache : true,
                type : "POST",
                url : ctx + "system/productVersion/add",
                data : {
                    "productId": productId,
                    "productName": productName,
                    "version": version,
                    "name": versionName,
                    "isPublished": isPublished
                },
                async : false,
                error : function(request) {
                    $.modal.alertError("系统错误");
                },
                success : function(data) {
                    $.operate.successCallback(data);
                }
            });
        }
	</script>
</body>
</html>
